package com.spring.provideronetest.test;

import java.util.*;

/**
 * @auther zhangxiangtao
 * @date 2021/1/15
 */
public class Girl {
	public static void main(String[] args) {
		int[] nums = { -2,0,1,1,2};
		Arrays.sort(nums);
		List<List<Integer>> list = new ArrayList<>();
		int i =0;
		int s = 1;
		int j = nums.length-1;
		sum( list,i,s,j,nums);
		System.out.println(list);
		return ;

	}


	private static void  sum(List<List<Integer>> list,int i,int s,int j,int[] nums){
		if(j<=i+1){
			return;
		}
		while(s<j){
			if(nums[i] + nums[s] + nums[j] == 0){
				List<Integer> ll = new ArrayList<>();
				ll.add(nums[i]);
				ll.add(nums[s]);
				ll.add(nums[j]);
				list.add(new ArrayList<>(ll));
				break;
			}
			if(nums[i] + nums[s] + nums[j] > 0){
				break;
			}
			s++;
		}
		int m = 0;
		while(i+2 < j && nums[i]==nums[i+1]) {
			m++;
		}
		sum(list,i+1+m,i+2+m,j,nums);
		m = 0;
		while( j-1 >i && nums[j] == nums[j-1] ){
			m++;
		}
		sum( list,i,i+1,j-m-1,nums);

	}

}
